package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TmcPropertyNotice;
import com.ruoyi.system.service.ITmcPropertyNoticeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物业公告Controller
 * 
 * @author ruoyi
 * @date 2021-04-08
 */
@RestController
@RequestMapping("/system/property")
public class TmcPropertyNoticeController extends BaseController
{
    @Autowired
    private ITmcPropertyNoticeService tmcPropertyNoticeService;

    /**
     * 查询物业公告列表
     */
    //@PreAuthorize("@ss.hasPermi('system:notice:list')")
    @GetMapping("/list")
    public TableDataInfo list(TmcPropertyNotice tmcPropertyNotice)
    {
        startPage();
        List<TmcPropertyNotice> list = tmcPropertyNoticeService.selectTmcPropertyNoticeList(tmcPropertyNotice);
        return getDataTable(list);
    }
    @GetMapping("/queryPropertyNotice")
    public TableDataInfo queryPropertyNotice()
    {
        List<TmcPropertyNotice> list = tmcPropertyNoticeService.queryPropertyNotice();
        return getDataTable(list);
    }

    /**
     * 导出物业公告列表
     */
    //@PreAuthorize("@ss.hasPermi('system:notice:export')")
    @Log(title = "物业公告", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TmcPropertyNotice tmcPropertyNotice)
    {
        List<TmcPropertyNotice> list = tmcPropertyNoticeService.selectTmcPropertyNoticeList(tmcPropertyNotice);
        ExcelUtil<TmcPropertyNotice> util = new ExcelUtil<TmcPropertyNotice>(TmcPropertyNotice.class);
        return util.exportExcel(list, "notice");
    }

    /**
     * 获取物业公告详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:notice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tmcPropertyNoticeService.selectTmcPropertyNoticeById(id));
    }

    /**
     * 新增物业公告
     */
    //@PreAuthorize("@ss.hasPermi('system:notice:add')")
    @Log(title = "物业公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TmcPropertyNotice tmcPropertyNotice)
    {
        return toAjax(tmcPropertyNoticeService.insertTmcPropertyNotice(tmcPropertyNotice));
    }

    /**
     * 修改物业公告
     */
    //@PreAuthorize("@ss.hasPermi('system:notice:edit')")
    @Log(title = "物业公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TmcPropertyNotice tmcPropertyNotice)
    {
        return toAjax(tmcPropertyNoticeService.updateTmcPropertyNotice(tmcPropertyNotice));
    }

    /**
     *
     * 删除物业公告
     */
    //@PreAuthorize("@ss.hasPermi('system:notice:remove')")
    @Log(title = "物业公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tmcPropertyNoticeService.deleteTmcPropertyNoticeByIds(ids));
    }
}
